<?php
// 本类由系统自动生成，仅供测试用途
class ManagerAction extends Action {

	
	

    //公版
    public function query(){
    	header("Content-Type:text/html; charset=utf-8");
      $environment=D('Environment');$para=D('Para');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];
      
      $tm=date('Y.m.d',time());
      $this->assign('tm',$tm);

      $arr_parao=$para->getparao();$parao=$arr_parao['data'];
      $this->assign('parao',$parao);

      $this->assign('banner','管理员');

      $this->assign('ttl','管理员');
      $this->display('query');
  
    }

    public function dochangepara(){
      header("Content-Type:text/html; charset=utf-8");
      $para=D('Para');

      $para->update(gp());


      $this->ajaxReturn($data,'json');
      
    }

    public function poll(){
      header("Content-Type:text/html; charset=utf-8");
      $environment=D('Environment');
      $arr_usross=$environment->setenvironment(MODULE_NAME);
      
      $this->assign('ttl','轮询中...');
      $this->display('poll');
      
    }

    public function doqingkongdb(){
      header("Content-Type:text/html; charset=utf-8");
      $item=M('item');$part=M('part');$parttype=M('parttype');$plan=M('plan');$ps=M('ps');
      $item->where('1=1')->delete();
      $part->where('1=1')->delete();
      $parttype->where('1=1')->delete();
      $plan->where('1=1')->delete();
      $ps->where('1=1')->delete();
      $this->ajaxReturn($data,'json');     
    }

    public function dopoll(){
      header("Content-Type:text/html; charset=utf-8");
      $plan=D('Plan');$ps=D('Ps');
   
      //不断更新物料剩余时间
      //情况①非（配送和完成状态）的剩余时间
      $arr_planls=$plan->getplanlsofnotpsandnotfinish();$planls=$arr_planls['data'];
      foreach($planls as $planv){
        $arr_leavetm=$ps->gettheorypsleavetm($planv);$leavetm=$arr_leavetm['data'];
        $arr_psls=$ps->getpslsbyplanid($planv['planid']);$psls=$arr_psls['data'];
        foreach($psls as $psv){
          $dt['psleavetm']=$leavetm;
          $ps->mdf($dt,$psv['psid']);
        }
      }
      //情况②（配送和完成状态）的剩余时间
      // $arr_planls=$plan->getplanlsofnotstartandnotready();$planls=$arr_planls['data'];
      // foreach($planls as $planv){
      //   $arr_leavetm=$ps->gettheorypsleavetm($planv);$leavetm=$arr_leavetm['data'];
      //   $arr_psls=$ps->getpslsbyplanid($planv['planid']);$psls=$arr_psls['data'];
      //   foreach($psls as $psv){
      //     $dt['psleavetm']=$leavetm;
      //     $ps->mdf($dt,$psv['psid']);
      //   }
      // }


      //不断检测该时间段下是否需要自动确定plan
      $his=date('H:i:s',time());$ymd=date('Y-m-d',time());
      if($his>"07:30:00"&&$his<"19:30:00"){
        $banciid=1;
      }else if($his>="19:30:00"){
        $banciid=2;
      }else if($his>="00:00:00"&&$his<="07:30:00"){
        $tm=strtotime($ymd)-24*3600;
        $ymd=date('Y-m-d',$tm);
        $banciid=2;
      }
      $arr_planls=$plan->getplanlsbyplantmandbanciidwithstat0($ymd,$banciid);$planls=$arr_planls['data'];
      // logger(je($planls),'log/log_'.date('Y-m-d',time()).'.txt');
      foreach($planls as $planv){
        $plan->queding($planv['planid']);
        $ps->changestatbyqueding($planv['planid']);
      }


      $this->ajaxReturn($data,'json');
      
    }

    

}